<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>点名</title>
  <link rel="stylesheet" href="../css/reset.css">
  <link rel="stylesheet" href="../css/home.css">
</head>

<body>

  <div class="header">
    <div class="header-in container">大冤种提取器</div>
    <div class="countdown container">10</div>
  </div>
  <div class="control">
    <div class="control-in container">
      <button class="btn-start" type="button">开始</button>
      <button class="btn-end" type="button">结束</button>
    </div>
  </div>

  <div class="stu m-t10">
    <div class="stu-in container">
      <div class="group">
        <h3>第1组</h3>
        <ul>
          <li>黄嘉辉</li>
          <li>杨韵璋</li>
          <li>廖宏妃</li>
          <li>张长春</li>
        </ul>
      </div>
      <div class="group">
        <h3>第2组</h3>
        <ul>
          <li>林萃</li>
          <li>周志超</li>
          <li>刘长生</li>
          <li>崔梦娇</li>
        </ul>
      </div>
      <div class="group">
        <h3>第3组</h3>
        <ul>
          <li>郭嘉辉</li>
          <li>刘佳富</li>
          <li>郭浩</li>
          <li>周波</li>
          <li>林学君</li>
        </ul>
      </div>
      <div class="group">
        <h3>第4组</h3>
        <ul>
          <li>朱永康</li>
          <li>张健飞</li>
          <li>王依萍</li>
          <li>范声强</li>
        </ul>
      </div>
      <div class="group">
        <h3>第5组</h3>
        <ul>
          <li>刘家锦</li>
          <li>苏陈凤</li>
          <li>文江宜</li>
          <li>刘国梁</li>
        </ul>
      </div>
    </div>
  </div>

  <script>
    const stus = document.querySelectorAll('li')
    const startBtn = document.querySelector('.btn-start')
    const endBtn = document.querySelector('.btn-end')
    let setTimeoutId = null

    function clearStuActiveAll() {
      stus.forEach(stu => {
        stus.classList.remove('active')
      })

    }


    let setRandomStuAddActive = () => {
      clearStuActiveAll()

      let rand = Math.floor(Math.random() * stus.length)

      stus[rand].classList.add('active')

      let setTimeoutId = setTimeout(setRandomStuAddActive, 1000);
    }

    startBtn.addEventListener('click', () => {
      setRandomStuAddActive()
    })
    endBtn.addEventListener('click', () => {
      clearTimeout(setTimeoutId)
    })


  </script>

</body>

</html>